import json

import pytest

from API.course import CourseAPI
from API.login import LoginAPI

class TestAddCourse:
    uuid=None
    token=None
    def setup_method(self):
        # 实例化
        self.login_api=LoginAPI()
        self.course_api=CourseAPI()
        res_v=self.login_api.get_verify_code()
        TestAddCourse.uuid=res_v.json()["uuid"]
        test_data = {

            "username": "admin",
            "password":"HM_2023_test",
            "code": "2",
            "uuid": TestAddCourse.uuid
        }
        res_login_success = self.login_api.login(test_data=test_data)
        print(res_login_success.json())
        TestAddCourse.token=res_login_success.json()["token"]
    def teardown(self):
        pass

    def test01_select_course(self):

        res_add_course = self.course_api.select_course(test_data="?name=测试开发课程1", token=TestAddCourse.token)
        # print(res_add_course.json())
        assert res_add_course.status_code==200
        assert "成功" in res_add_course.text
        assert 200==res_add_course.json()["code"]
        # 2未登录
    def test02_select_course(self):
        select_course_data ="?name=测试开发课程1&subject=6&price=78&applicablePerson=2&info=测试开发提升课程，适合有基础的人学习"

        res_add_course = self.course_api.select_course(test_data=select_course_data, token="")

        assert res_add_course.status_code==200
        assert "失败" in res_add_course.text
        assert 401==res_add_course.json()["code"]

